package top.cross.webapp.common.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import org.json.JSONObject;

//import com.amap.querry.log.Logger;
//import com.emm.innerapp.tools.EMMInnerAppToolsUtil;
//import com.kdgc.bluetoothprinter.PrintActivity;

/**
 * Created by 55030 on 2018/6/6.
 */

public class WebviewMethodUtil {

    public static String judgePackageInstall(Context context, String packageName) throws Exception{
        PackageInfo packageInfo = getpackageinfo(context, packageName);
        JSONObject jsonObject = new JSONObject();
        if (packageInfo == null) {
            jsonObject.put("isinstall", false);
            jsonObject.put("versionName", "");
            jsonObject.put("packageName", packageName);
        } else {
            jsonObject.put("isinstall", true);
            jsonObject.put("versionName", packageInfo.versionName);
            jsonObject.put("packageName", packageInfo.packageName);
        }
        return jsonObject.toString();
    }

    public static PackageInfo getpackageinfo(Context context, String packageName) {
        try {
            final PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            String s = "#";
            return packageInfo;
        } catch (Exception ex) {
            boolean b = ex instanceof PackageManager.NameNotFoundException;
            if (b) {
//                ex.printStackTrace();
                return null;
            }
//            ex.printStackTrace();
        }
        return null;
    }

}
